home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / recode.lha / recode-3.2.4 / lat1ltex.c < prev    next >
C/C++ Source or Header  |  1992-08-26  |  7KB  |  162 lines

  1. /* Conversion of files between different charsets and usages.
  2.    Copyright (C) 1990 Free Software Foundation, Inc.
  3.    Francois Pinard <pinard@iro.umontreal.ca>, 1988.
  4.  
  5.    This program is free software; you can redistribute it and/or modify
  6.    it under the terms of the GNU General Public License as published by
  7.    the Free Software Foundation; either version 2, or (at your option)
  8.    any later version.
  9.  
  10.    This program is distributed in the hope that it will be useful, but
  11.    WITHOUT ANY WARRANTY; without even the implied warranty of
  12.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.    General Public License for more details.
  14.  
  15.    You should have received a copy of the GNU General Public License
  16.    along with this program; if not, write to the Free Software
  17.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. */
  19.  
  20. #define STEP    latin1_latex
  21. #include <stdio.h>
  22. #include "common.h"
  23.  
  24. extern int diacritics_only;
  25.  
  26. struct translation
  27. {
  28.   int code;            /* code being translated */
  29.   char *string;            /* translation string */
  30. };
  31.  
  32. struct translation diacritic_translations [] =
  33. {
  34.   {0300, "\\`A"},        /* capital A with grave accent */
  35.   {0301, "\\'A"},        /* capital A with acute accent */
  36.   {0302, "\\^A"},        /* capital A with circumflex accent */
  37.   {0303, "\\~A"},        /* capital A with tilde */
  38.   {0304, "\\\"A"},        /* capital A diaeresis */
  39.   {0305, "\\AA{}"},        /* capital A with ring above */
  40.   {0306, "\\AE{}"},        /* capital diphthong A with E */
  41.   {0307, "\\c{C}"},        /* capital C with cedilla */
  42.   {0310, "\\`E"},        /* capital E with grave accent */
  43.   {0311, "\\'E"},        /* capital E with acute accent */
  44.   {0312, "\\^E"},        /* capital E with circumflex accent */
  45.   {0313, "\\\"E"},        /* capital E with diaeresis */
  46.   {0314, "\\`I"},        /* capital I with grave accent */
  47.   {0315, "\\'I"},        /* capital I with acute accent */
  48.   {0316, "\\^I"},        /* capital I with circumflex accent */
  49.   {0317, "\\\"I"},        /* capital I with diaeresis */
  50.   {0321, "\\~N"},        /* capital N with tilde */
  51.   {0322, "\\`O"},        /* capital O with grave accent */
  52.   {0323, "\\'O"},        /* capital O with acute accent */
  53.   {0324, "\\^O"},        /* capital O with circumflex accent */
  54.   {0325, "\\~O"},        /* capital O with tilde */
  55.   {0326, "\\\"O"},        /* capital O with diaeresis */
  56.   {0330, "\\O{}"},        /* capital O with oblique stroke */
  57.   {0331, "\\`U"},        /* capital U with grave accent */
  58.   {0332, "\\'U"},        /* capital U with acute accent */
  59.   {0333, "\\^U"},        /* capital U with circumflex accent */
  60.   {0334, "\\\"U"},        /* capital U with diaeresis */
  61.   {0335, "\\'Y"},        /* capital Y with acute accent */
  62.   {0337, "\\ss{}"},        /* small german sharp s */
  63.   {0340, "\\`a"},        /* small a with grave accent */
  64.   {0341, "\\'a"},        /* small a with acute accent */
  65.   {0342, "\\^a"},        /* small a with circumflex accent */
  66.   {0343, "\\~a"},        /* small a with tilde */
  67.   {0344, "\\\"a"},        /* small a with diaeresis */
  68.   {0345, "\\aa{}"},        /* small a with ring above */
  69.   {0346, "\\ae{}"},        /* small diphthong a with e */
  70.   {0347, "\\c{c}"},        /* small c with cedilla */
  71.   {0350, "\\`e"},        /* small e with grave accent */
  72.   {0351, "\\'e"},        /* small e with acute accent */
  73.   {0352, "\\^e"},        /* small e with circumflex accent */
  74.   {0353, "\\\"e"},        /* small e with diaeresis */
  75.   {0354, "\\`\\i{}"},        /* small i with grave accent */
  76.   {0355, "\\'\\i{}"},        /* small i with acute accent */
  77.   {0356, "\\^\\i{}"},        /* small i with circumflex accent */
  78.   {0357, "\\\"\\i{}"},        /* small i with diaeresis */
  79.   {0361, "\\~n"},        /* small n with tilde */
  80.   {0362, "\\`o"},        /* small o with grave accent */
  81.   {0363, "\\'o"},        /* small o with acute accent */
  82.   {0364, "\\^o"},        /* small o with circumflex accent */
  83.   {0365, "\\~o"},        /* small o with tilde */
  84.   {0366, "\\\"o"},        /* small o with diaeresis */
  85.   {0370, "\\o{}"},        /* small o with oblique stroke */
  86.   {0371, "\\`u"},        /* small u with grave accent */
  87.   {0372, "\\'u"},        /* small u with acute accent */
  88.   {0373, "\\^u"},        /* small u with circumflex accent */
  89.   {0374, "\\\"u"},        /* small u with diaeresis */
  90.   {0375, "\\'y"},        /* small y with acute accent */
  91.   {0377, "\\\"y"},        /* small y with diaeresis */
  92.   {0, NULL}
  93. };
  94.  
  95. struct translation other_translations [] =
  96. {
  97.   {0043, "\\#"},
  98.   {0044, "\\$"},
  99.   {0045, "\\%"},
  100.   {0046, "\\&"},
  101.   {0134, "\\backslash{}"},
  102.   {0137, "\\_"},
  103.   {0173, "\\{"},
  104.   {0175, "\\}"},
  105.   {0240, "\\ "},        /* no-break space */
  106.   {0241, "!'"},            /* inverted exclamation mark */
  107.   {0247, "\\S{}"},        /* paragraph sign, section sign */
  108.   {0250, "\\\"{}"},        /* diaeresis */
  109.   {0253, "``"},            /* left angle quotation mark */
  110.   {0254, "\\neg{}"},        /* not sign */
  111.   {0255, "\\-"},        /* soft hyphen */
  112.   {0260, "\\mbox{$^\\circ$}"},    /* degree sign */
  113.   {0261, "\\mbox{$\\pm$}"},    /* plus-minus sign */
  114.   {0262, "\\mbox{$^2$}"},    /* superscript two */
  115.   {0263, "\\mbox{$^3$}"},    /* superscript three */
  116.   {0264, "\\'{}"},        /* acute accent */
  117.   {0265, "\\mbox{$\\mu$}"},    /* small greek mu, micro sign */
  118.   {0267, "\\cdotp"},        /* middle dot */
  119.   {0270, "\\,{}"},        /* cedilla */
  120.   {0271, "\\mbox{$^1$}"},    /* superscript one */
  121.   {0273, "''"},            /* right angle quotation mark */
  122.   {0274, "\\frac1/4{}"},    /* vulgar fraction one quarter */
  123.   {0275, "\\frac1/2{}"},    /* vulgar fraction one half */
  124.   {0276, "\\frac3/4{}"},    /* vulgar fraction three quarters */
  125.   {0277, "?'"},            /* inverted question mark */
  126.   {0, NULL}
  127. };
  128.  
  129. void
  130. STEP (FILE *input_file, FILE *output_file)
  131. {
  132.   char *translation_table[256];    /* one string for each character */
  133.   char character_pool[256];    /* for some strings of translation_table */
  134.   struct translation *cursor;    /* cursor in translation arrays */
  135.   int input_char;        /* current character */
  136.   const char *output_string;    /* translated characters */
  137.  
  138.   for (input_char = 0; input_char < 128; input_char++)
  139.     {
  140.       translation_table[input_char] = character_pool + 2*input_char;
  141.       translation_table[input_char][0] = input_char;
  142.       translation_table[input_char][1] = '\0';
  143.     }
  144.   for (input_char = 128; input_char < 256; input_char++)
  145.     translation_table[input_char] = NULL;
  146.  
  147.   for (cursor = diacritic_translations; cursor->code; cursor++)
  148.     translation_table[cursor->code] = cursor->string;
  149.   if (!diacritics_only)
  150.     for (cursor = other_translations; cursor->code; cursor++)
  151.       translation_table[cursor->code] = cursor->string;
  152.  
  153.   while (input_char = getc (input_file), input_char != EOF)
  154.     if (output_string = translation_table[input_char], output_string)
  155.       do
  156.     {
  157.       putc (*output_string, output_file);
  158.       output_string++;
  159.     }
  160.       while (*output_string);
  161. }
  162.